<?php

class BoardModel
{
    private $boardModelKeyPrefix=   'B/';

    public function postBoard($info)/*{{{*/
    {
        if (empty($info['foundUid']) || empty($info['title'])   ||  empty($info['content']))
        {
            empty($info['foundUid'])    &&  AC::$errorNo    =   'BM001';
            empty($info['title'])       &&  AC::$errorNo    =   'BM002';
            empty($info['content'])     &&  AC::$errorNo    =   'BM003';

            return  FALSE;
        }

        $data   =   array();
        empty($info['startTime'])   &&  $info['startTime']  =   AC::SERVER_TIME;
        empty($info['params'])      &&  $info['params']     =   NULL;
        if (isset($info['status'])  &&  empty($info['status']))
        {
            $data['status'] =   0;
        }

        $data['type']       =   $info['type'];
        $data['title']      =   $info['title'];
        $data['content']    =   $info['content'];
        $data['params']     =   $info['params'];
        $data['foundUid']   =   $info['foundUid'];
        $data['founder']    =   $info['founder'];
        $data['startTime']  =   $info['startTime'];
        $data['foundTime']  =   AC::SERVER_TIME;

        $key    =   $this->boardModelKeyPrefix. 0;
        $result =   Storage::addData($key, $data);

        return  $result;
    }/*}}}*/

    public function updateBoard($info)/*{{{*/
    {
        if (empty($info['modifyUid'])   ||  empty($info['id']))
        {
            AC::$errorNo    =   'BM004';
            return  FALSE;
        }
        if (isset($info['title'])   &&  empty($info['title']))
        {
            AC::$errorNo    =   'BM002';
            return  FALSE;
        }
        if (isset($info['content']) &&  empty($info['content']))
        {
            AC::$errorNo    =   'BM003';
            return  FALSE;
        }

        $data   =   array();
        $data['modifier']   =   $info['modifier'];
        $data['modifyTime'] =   AC::SERVER_TIME;

        isset($info['title'])       &&  $data['title']      =   $info['title'];
        isset($info['content'])     &&  $data['content']    =   $info['content'];
        isset($info['params'])      &&  $data['params']     =   $info['params'];
        isset($info['startTime'])   &&  $data['startTime']  =   $info['startTime'];
        isset($info['status'])      &&  $data['status']     =   $info['status'];

        $key    =   $this->boardModelKeyPrefix. 0;
        $where  =   array('id' => $info['id']);
        $result =   Storage::setConditionData($key, $data, $where);
        return  $result;
    }/*}}}*/

    public function removeBoard($info)/*{{{*/
    {
        if (empty($info['modifyUid'])   ||  empty($info['id']))
        {
            AC::$errorNo    =   'BM004';
            return  FALSE;
        }

        $key    =   $this->boardModelKeyPrefix. $info['id'];
        $where  =   array('id'  =>  $info['id']);
        $result =   Storage::delConditionData($key, $where);

        return  $result;
    }/*}}}*/

    public function getBoardList($info)/*{{{*/
    {
        if (isset($info['status']))
        {
            $where  =   NULL;
            $orderBy=   ' foundTime DESC ';
        }
        else
        {
            $where  =   ' startTime < '. AC::SERVER_TIME. ' AND status = 0 ';
            $orderBy=   ' startTime DESC ';
        }
        $key    =   $this->boardModelKeyPrefix. 0;
        $result =   Storage::getConditionManyData($key, $where, $orderBy);

        return  $result;
    }/*}}}*/

}

